@include ("blog.header")
<div class="container-fluid">

  <form class="form-horizontal" method="post" action="/blog/{{$data->id}}">
   {{csrf_field()}}
   {{method_field('PATCH')}}
       
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">标题</label>
    <div class="col-sm-8">
      <input type="title" class="form-control" name="title" value="{{$data->title}}">
    </div>
  </div>


  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">内容</label>
    <div class="col-sm-8">
       <script id="editor" name="content" type="text/plain" style="height:200px;"></script>
       <script>
         var ue = UE.getEditor('editor');
       </script>
      
    </div>
  </div>
   
  
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-default">提交</button>
      <button type="button" class="btn btn-default">预览</button>
    </div>
  </div>
</form>

<div class="panel panel-default" style="display:none" id="show">
      <div class="panel-body">
     
        <span class="btn btn-info">标题</span>
        <span id="title"></span>
        <span class="btn btn-info">内容</span>
        <span id="content"></span>
        <a href="" class="btn btn-info">阅读</a>
        <a href="" class="btn btn-info">修改</a>
        <input type="hidden" name="_method" value="DELETE">
        <button type="submit" class="btn btn-danger">删除</button> 
                
            
        </div>
    </div>
   
@include ('blog.footer')
<script>

//点击事件
  $("button[type='button']").click(function(){
      switch($(this).html()){
        case "预览":


        var title = $("input[name='title']").attr("value");
        var content = $("textarea").val();
        //AJAX请求设置头部
        $.ajaxSetup({
         headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
        });
        //AJAX
        $.post("/blog/sh",{title:title,content:content},function(data){
         
          //alert(data['title']);
          $("#title").html(data["title"]);
          $("#content").html(data['content']);
        });
        $("#show").show();
        $(this).html("取消预览");
        break;
        case "取消预览":
        $("#show").hide();
        $(this).html("预览");
        break;
      }
  });

</script>